package com.lanou.dllo.soccernews.database;

import com.lanou.dllo.soccernews.application.BaseApplication;
import com.lanou.dllo.soccernews.bean.greendao.ArticlesEntity;
import com.lanou.dllo.soccernews.bean.greendao.CollectionBeanArticlesEntity;
import com.lanou.dllo.soccernews.bean.greendao.DaoSession;

import java.util.List;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by dllo on 15/11/2.
 */
public class CollectionBeanDBhelp {
    private static CollectionBeanDBhelp collectionBeanDBhelp;
    private static DaoSession daoSession;

    private CollectionBeanDBhelp() {

    }

    public static CollectionBeanDBhelp getInstance() {
        if (collectionBeanDBhelp == null) {
            collectionBeanDBhelp = new CollectionBeanDBhelp();
            daoSession = BaseApplication.getDaoSession();
        }

        return collectionBeanDBhelp;
    }

    public List<CollectionBeanArticlesEntity> getCollectionBeanArticlesEntity() {
        QueryBuilder<CollectionBeanArticlesEntity> qb = daoSession.getCollectionBeanArticlesEntityDao().queryBuilder();
        return qb.list();
    }

    public void addCollectionBeanArticlesEntity(List<CollectionBeanArticlesEntity> articles) {
        daoSession.getCollectionBeanArticlesEntityDao().insertInTx(articles);
    }

}
